<template>
	<view>
		<u-navbar :title="$t('我的订单')" background="{ background: '#fff' }" title-color="#000" back-icon-color="#000"></u-navbar>
		<u-sticky :enable="enable">
			<u-tabs active-color="#070820" bg-color="#fff" inactive-color="#999" name="cate_name" :list="navList" :is-scroll="false" :current="current"
				@change="change"></u-tabs>
		</u-sticky>
		<view class="orderList">
			<view class="list" v-for="(item,idx) in orderList" :key="idx" @click="details(item)">
				<view class="tit n-flex-row n-justify-between">
					<view class="num">{{ $t("订单时间") }}：{{item.create_time}}</view>
					<view class="state">{{item.status_text}}</view>
				</view>
				<view class="goods">
					<image :src="item.goods_data.image" mode=""></image>
					<view class="info">
						<view class="gtit">
							{{item.goods_data.title}}
						</view>
						<view class="peice n-flex-row n-justify-between">
							<view class="p">￥{{item.price}}</view>
							<view class="num">x{{item.number}}</view>
						</view>
					</view>
				</view>
				<view class="total">
					<text class="shu">{{ $t("共") }}{{item.number}}{{ $t("件") }} | </text><text style="margin-left: 10rpx;">{{ $t("合计") }}：￥</text><text class="pri">{{item.order_price}}</text>
				</view>
			</view>
		</view>
		<u-empty text="暂无订单" :show="show" mode="order" margin-top="400"></u-empty>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navList: [{
					cate_name: this.$t('全部') 
				}, {
					cate_name: this.$t('待发货'),
				}, {
					cate_name: this.$t('待收货'),
				}, {
					cate_name:  this.$t('已完成'),
				}],
				current: 0,
				orderList:[],
				show:false,
				page:1,
				enable:true,
			}
		},
		onLoad(option) {
			this.current = option.idx
			if (uni.getStorageSync("user")) {
				this.getData()
			}
			uni.$on('uporder',()=> {
				console.log("调用");
				this.getData()
			})
		},
		// 触底
		onReachBottom() {
			if (this.orderList.length < this.page * 10) {
				return
			}
			this.page++;
			this.getData()
		},
		onUnload() {
			uni.$off('uporder')
		},
		onHide() {
			this.enable= false
		},
		methods: {
			change(index) {
				this.current = index;
				this.orderList = [];
				this.page = 1;
				this.getData()
			},
			details(info){
				uni.navigateTo({
					url:'/pagesB/pages/my/orderDetails?order_id='+info.id
				})
			},
			getData(){
				uni.showLoading({
					title:"加载中"
				})
				this.$http({
					url: "api/order/get_goods_order",
					data:{
						status:this.current,
						page:this.page
					}
				}).then(res => {
					uni.hideLoading()
					console.log(res);
					if (res.data.code == 1) {
						if(res.data.data.length == 0){
							this.show = true
						}else{
							this.show = false
						}
						this.orderList = this.orderList.concat(res.data.data);
					}else{
						this.$tip.tip(res.data.msg)
						this.show = true
					}
				}).catch(err => {});
			},
		}
	}
</script>

<style>
@import url("../../../static/css/order.css");
</style>